#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2016 lizongzhe 
#
# Distributed under terms of the MIT license.
import urllib
from django.core.cache import cache

def sample_job(func):
    def job_func(job):
        try:
            cache_key = urllib.quote_plus(job.name.encode('utf-8'))
            result =  cache.get(cache_key)
            if not result:
                result = func(job)
                cache.set(cache_key, result, 86400) ## cache one day
            return result
        except Exception as e:
            job.logger.error(type(e))
            job.logger.error(e)
            job.logger.error(traceback.format_exc())
        raise e
    return job_func



